﻿(function($) {
    $.fn.LinkPageSelect = function(options) {
        var o = jQuery.extend({
            obj: null,
            event: ["keyup", "blur"],
            context: true, //如果为false则匹配下拉框的value，默认匹配下拉框文本
            full: true //是否完全匹配
        }, options);
        var _self = this;
        var jobj = o.obj
        if (jobj == null) { return _self; }
        var ev = o.event;
        jQuery.each(ev, function(i, n) {
        
            _self.bind(n, function() {
                var v = jQuery.trim(_self.val());
                    if(v=="")
                    {
                        v="0";
                    }
                    if (o.full) {
                        o.context == true ? $(jobj + ">option[value='" + v + "']").attr("selected", "selected") : $(jobj + ">option[value='" + v + "']").attr("selected", "selected"); //完全匹配
                    }
                    else {
                        o.context == true ? $(jobj + ">option[value^='" + v + "']").attr("selected", "selected") : $(jobj + ">option[value^='" + v + "']").attr("selected", "selected"); //模糊匹配
                    }
            });
        });
        return _self;
    };
})(jQuery);